if (!(window.File && window.FileReader && window.FileList && window.Blob)) {
  throw new Error('当前浏览器对FileAPI的支持不完善')
}
function handleFileSelect(event) {
  let { files } = event.target
  if (!files.length) {
    return
  }

  const handleLoadStart = (ev, file) =>
    console.log(`>>> Start load ${file.name}`)
  const handleProgress = (ev, file) => {
    console.log('ev: ', ev)
    if (!ev.lengthComputable) {
      return
    }
    // 计算进度，并且以百分比形式展示
    const percent = Math.round((ev.loaded / ev.total) * 100)
    console.log(`<<< Loding ${file.name}, progress is ${percent}%`)
  }

  for (let file of files) {
    const reader = new FileReader()
    reader.onloadstart = (ev) => handleLoadStart(ev, file)
    reader.onprogress = (ev) => handleProgress(ev, file)
    reader.readAsArrayBuffer(file)
  }
}

document
  .querySelector('#files')
  .addEventListener('change', handleFileSelect, false)
